<!DOCTYPE html>
<html>
<head>
    <title>js面向对象-修正constructor的指向错误</title>
    <meta charset="utf-8"/>
    <script src="../../js/jquery-1.10.1.min.js"></script>
    <script src="../../js/json2.js"></script>
    <script>

        var zhang = new Employee("ZhangSan", "1234");

        console.log(zhang.constructor === Employee); // false

        console.log(zhang.constructor === Object); // true

        function Person(name) {
            this.name = name;
        }

        Person.prototype = {
            getName: function() {
                return this.name;
            }
        };

        function Employee(name, employeeID) {
            this.name = name;
            this.employeeID = employeeID;
        }

        Employee.prototype = new Person();

        Employee.prototype.constructor = Employee;

        Employee.prototype.getEmployeeID = function() {

            return this.employeeID;

        };

        var zhang = new Employee("ZhangSan", "1234");

        console.log(zhang.constructor === Employee); // true

        console.log(zhang.constructor === Object); // false

    </script>
</head>
<body>

</body>
</html>